﻿{include file=header.html}
<script language="javascript" type="text/javascript" src="{res file=DatePicker/WdatePicker.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery-1.2.6.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/common.js}"></script>
<script language="javascript" type="text/javascript">
$(function() {
	$('th[type="order"]').click(function() {
		var order = $(this).attr('field') + '-' + $(this).attr('order');
		$('#order').val(order);
		$('input[name="search"]').click();
	}).css({'cursor': 'pointer', 'color': '#36c'});
	var order = $('#order').val().split('-');
	var field = $('th[type="order"][field="' + order[0] + '"]');
	if (order[1] == 'ASC') {
		field.attr('order', 'DESC').text(field.text() + '↑');
	} else {
		field.attr('order', 'ASC').text(field.text() + '↓');
	}
	if (order[0] != 'arrival_date') {
		$('th[type="order"][field="arrival_date"]').attr('order', 'DESC');
	}
	var isdblclick=0;
	$('td[type="edit"]').dblclick(function() {
		//var html = $(this).text().replace('<br>', '');
		
		if(isdblclick==0)
			 {
			   var html = $(this).html();
			 }
			 else if(isdblclick==1)
			 {
				var html = $(this).text();
			 }
			 isdblclick=1;
		var textarea = $('<textarea style="width:100%; height:50px;">' + html + '</textarea>');
		textarea.blur(function() {
			var _this = $(this);
			var data = _this.val();
			var url = 'index.php?app=sample&act=edit_desc&id=' + _this.parent().attr('sample_id');
			$.post(url, {'description': data}, function(msg) {
				if (msg == 'success') {
				    isdblclick=0;
					_this.parent().html(nl2br(data));
				} else {
					alert(msg);
				}
			});
		});
		$(this).html('').append(textarea);
		textarea.focus();
	});
});
function nl2br (str) {
	var arr = str.split('\n');
	var ret = '';
	for (var i = 0; i < arr.length; i++) {
		ret += arr[i];
		if (i != arr.length - 1) {
			ret += '<br>\n';
		}
	}
	return ret;
}
</script>
<body>
<!--收起展开 2013-2-27 -->
<!--<div class="sub-body" style="padding:20px 25px 0 25px;">
  <a href="" onClick="$('#search_box').slideToggle();return false;">收起/展开</a>
</div> -->
<!--收起展开 2013-2-27 -->
<style>
#search_frame .tab-frame td {padding:1px 5px;}
</style>
<div class="sub-body" id="search_box">
  <h3 class="tab-title-1" style="display:none;"><span>待审批样板</span></h3>
  <div id="search_frame">
  <form method="get" action="{url app=sample&act=approve}">
  <input type="hidden" name="app" value="sample">
  <input type="hidden" name="act" value="approve">
    <table cellspacing="0" cellpadding="0" class="search" width="80%">
      <tr>
        <th width="100">到板日期：</th>
        <td width="200"><input type="text" name="arrival_date_start" class="input-6" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="{$smarty.get.arrival_date_start}" />
          至
          <input type="text" name="arrival_date_end" class="input-6" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="{$smarty.get.arrival_date_end}"/></td>
        <th width="100">板&nbsp;&nbsp;&nbsp; 号：</th>
        <td width="200"><input type="text" name="sample_sn" class="input-1" value="{$smarty.get.sample_sn}"/></td>
        <th width="100">品&nbsp;&nbsp;&nbsp; 牌：</th>
        <td width="200"><select name="brand_id" id="brand_id">
          <option value="0"></option>
		  <!--{foreach from=$brand_list item=brand}-->
          <option value="{$brand.brand_id}" {if $brand.brand_id == $smarty.get.brand_id}selected{/if}>{$brand.brand_name|escape}&nbsp;&nbsp;({$brand.company_name|escape})</option>
		  <!--{/foreach}-->
        </select></td>
        <td width="100" rowspan="2">&nbsp;<input name="search" type="submit" class="inquiry" value="{$lang.search}"/><!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="btn-2" value="清空条件" acttype="clear">--><input type="hidden" id="order" name="order" value="{if $smarty.get.order}{$smarty.get.order}{else}arrival_date-DESC{/if}" /></td>
      </tr>
      <tr>
        <th>买&nbsp;&nbsp;&nbsp; 手：</th>
        <td><select name="buyer_id" id="buyer_id">
          <option value="0"></option>
		  <!--{foreach from=$buyer_list item=buyer}-->
          <option value="{$buyer.user_id}" {if $buyer.user_id == $smarty.get.buyer_id}selected{/if}>{$buyer.user_name|escape}</option>
		  <!--{/foreach}-->
        </select></td>
        <th>工&nbsp;&nbsp;&nbsp; 厂：</th>
        <td><select name="factory_id">
          <option value="0"></option>
		  <!--{foreach from=$factory_list item=factory}-->
          <option value="{$factory.factory_id}" {if $factory.factory_id == $smarty.get.factory_id}selected{/if}>{$factory.factory_name|escape}</option>
		  <!--{/foreach}-->
        </select></td>
      <th>跟&nbsp;&nbsp;&nbsp; 单：</th>
        <td><select name="merch_id"{if !$user_manage && !$user_assistant} disabled{/if}>
          <option value="0"></option>
			<!--{foreach from=$merch_list item=merch}-->
			<option value="{$merch.user_id}"{if $user_manage || $user_assistant}{if $merch.user_id == $smarty.get.merch_id} selected{/if}{else}{if $visitor.user_id == $merch.user_id} selected{/if}{/if}>{$merch.user_name}</option>
			<!--{/foreach}-->
        </select></td>
        </tr>

      </table>
	</form>
  </div> 
    <h3 class="title-1" style="display:none;">{$lang.sample_status}</h3>
  <div class="tab_info">
  <div class="tab-title-1"><span>{$lang.sample_list}</span></div>
    <table width="100%" cellspacing="0" cellpadding="0" class="tab-display" id="tab-color1">
	<!--{if $user_manage}-->
		<tr style="display:none;">
			<td colspan="16" class="tab-align-l">
				<form method="get" action="{url app=sample&act=status}" id="search_form">
				{$lang.merchandiser}：
				<input type="hidden" name="app" value="sample" />
				<input type="hidden" name="act" value="status" />
				<select name="merch_id" onChange="document.getElementById('search_form').submit();">
					<option value="0">{$lang.select_pls}</option>
					<!--{foreach from=$merch_list item=merch}-->
					<option value="{$merch.user_id}" {if $merch_id == $merch.user_id}selected{/if}>{$merch.user_name}</option>
					<!--{/foreach}-->
				</select>
				</form>
			</td>
		</tr>
	<!--{/if}-->
      <tr>
        <th width="4%">{$lang.No}</th>
        <th width="8%" type="order" field="arrival_date" order="ASC">{$lang.arrival_date}</th>
        <th width="7%">{$lang.sample_sn}</th>
		<th width="7%">图片</th>
        <th width="7%" type="order" field="brand_name" order="ASC">{$lang.brand_name}</th>
        <th width="7%" type="order" field="buyer_id" order="ASC">{$lang.buyer_name}</th>
        <th width="7%" type="order" field="user_name" order="ASC">{$lang.merchandiser}</th>
        <th width="7%" type="order" field="factory_name" order="ASC">{$lang.factory_name}</th>
        <th width="8%" type="order" field="to_factory_date" order="DESC">{$lang.to_factory_date}</th>
        <th width="7%" type="order" field="sample_made_days" order="ASC">板期</th>
        <th width="7%">报价</th>
        <th width="7%" type="order" field="sample.status" order="ASC">{$lang.status}</th>
        <th width="9%">订单号</th>
		<th width="8%" type="order" field="predict_assign_date" order="ASC">预计交办日期</th>
      </tr>
	  <!--{foreach from=$sample_list item=sample name=sm}-->
      <tr{if $sample.sourcing_days > 7 || $sample.sample_made_days > 7} {/if}>
        <td>{$smarty.foreach.sm.iteration}</td>
        <td>{$sample.arrival_date|date:Y-m-d}</td>
        <td><a style="color:blue" href="
         {url app=sample&act=edit&id=$sample.sample_id}
        ">{$sample.sample_sn|escape}</a></td>
		<td><a href="{$sample.front_pic}" target="_blank"><img src="{$sample.front_pic}" width="80" style="border:none;" /></a></td>
        <td>{$sample.brand_name|escape}</td>
        <td>{$sample.member_name|escape}</td>
        <td>{$sample.user_name|escape}</td>
        <td>{$sample.factory_name|escape}</td>
        <td>{$sample.to_factory_date|date:Y-m-d}</td>
        <td><!--{if $sample.sample_made_days}-->{$sample.sample_made_days|escape}天<!--{/if}--></td>
        <td>{$sample.factory_price|escape}</td>
        <td>{$lang.statuies.$sample.status}</td>
        <td>{$sample.order_sn|escape}</td>
		<td>{$sample.predict_assign_date|date:Y-m-d}</td>
      </tr>
	  <!--{/foreach}-->
         </table>

  </div>
  {include file=page.html}
</div>

<script language="javascript" type="text/javascript" src="{res file=js/tab_color.js}"></script>
</body>
</html>